package com.gitee.cashzhang27.test.boot.other.controller;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import io.swagger.annotations.Api;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Cash Zhang
 * @version v1.0
 * @since 2019/05/22 14:26
 */
@Slf4j
@RequestMapping("/dishonest")
@RestController
@Api(value = "DishonestController", description = "失信人名单")
public class DishonestController {

  private static final String URL = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php";

  @GetMapping("page")
  public void page(int i) {
    Map<String, Object> paramMap = new HashMap<>();
    paramMap.put("resource_id", "6899");
    paramMap.put("query", "失信被执行人名单");
    paramMap.put("ie", "utf-8");
    paramMap.put("oe", "utf-8");
    paramMap.put("format", "json");
    paramMap.put("pn", String.valueOf(50 * i));
//    paramMap.put("rn",rn);
    String result = HttpUtil.get(URL, paramMap);
    System.out.println(result);
  }

  @GetMapping("get")
  public void get(String iname, String cardNum, String areaName) {
    // 姓名 身份证号 法院名称 案件号 日期 性别
    Map<String, Object> paramMap = new HashMap<>();
    paramMap.put("resource_id", "6899");
    paramMap.put("query", "失信被执行人名单");
    paramMap.put("cardNum", cardNum);
    paramMap.put("iname", iname);
    paramMap.put("areaName", areaName);
    paramMap.put("ie", "utf-8");
    paramMap.put("oe", "utf-8");
    paramMap.put("format", "json");
    String json = HttpUtil.get(URL, paramMap);
    JSONObject jsonObject = JSONUtil.parseObj(json);
    HashMap<Object, Object> firstMap = JSONUtil.toBean(jsonObject, HashMap.class);
    List<Map<String,Map<String,Object>>> list = (List<Map<String, Map<String, Object>>>) firstMap.get("data");
    if (list != null && list.size() > 0) {

      Map<String,Map<String,Object>> data=list.get(0);
      List<Map<String, Object>> result = (List<Map<String, Object>>) data.get("result");

      System.out.println(result);
    }
  }
}
